import { listQuestionVoByPageUsingPost } from "@/api/questionController";
import QuestionTable from "@/components/QuestionTable";

// 定义 Page 组件的 props 类型
interface Props {
  searchParams: Promise<Record<string, string>>;
} /**
 * 题目列表页面
 * @returns 题目列表页面
 */
const QuestionPage: React.FC<Props> = async ({ searchParams }) => {
  // const [messageApi, contextHolder] = message.useMessage();
  const searchContent = await searchParams;

  let questionList: API.QuestionVO[] = [];
  let total: number = 0;
  const params = {
    current: 1,
    pageSize: 10,
    sortField: "createTime",
    sortOrder: "descend",
    ...searchContent,
  };

  try {
    const { data } = await listQuestionVoByPageUsingPost({ ...params });
    questionList = data?.records ?? [];
    total = Number(data?.total) || 0;
  } catch (e: any) {
    // messageApi.error("获取题目列表失败" + e.message);
  }

  return (
    <div id="question-page">
      {/* {contextHolder} */}
      <QuestionTable
        initData={questionList}
        total={total}
        searchParams={searchContent}
      ></QuestionTable>
    </div>
  );
};
export default QuestionPage;
